package com.ahnu.tongue.config;

import com.google.common.util.concurrent.RateLimiter;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "rate-limit")
public class RateLimitConfig {
    
    private boolean enabled = true;
    private int defaultLimit = 300;
    private int uploadLimit = 60;
    
    @Bean(name = "defaultLimiter")
    public RateLimiter defaultRateLimiter() {
        return enabled ? RateLimiter.create(defaultLimit / 60.0) : RateLimiter.create(Double.MAX_VALUE);
    }
    
    @Bean(name = "uploadLimiter")
    public RateLimiter uploadRateLimiter() {
        return enabled ? RateLimiter.create(uploadLimit / 60.0) : RateLimiter.create(Double.MAX_VALUE);
    }
} 